{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1a81d735-d263-46b4-9294-420cb9d705bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>sentence_id</th>\n",
       "      <th>head</th>\n",
       "      <th>relation</th>\n",
       "      <th>tail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001020</td>\n",
       "      <td>10001020_0</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fans</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001020</td>\n",
       "      <td>10001020_0</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fan assemblies</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001020</td>\n",
       "      <td>10001020_0</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fan wheels</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001020</td>\n",
       "      <td>10001020_0</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>composite fan blades</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001020</td>\n",
       "      <td>10001020_0</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates</td>\n",
       "      <td>attachment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927524</th>\n",
       "      <td>9995315</td>\n",
       "      <td>9995315_37</td>\n",
       "      <td>wire winding space</td>\n",
       "      <td>is increased for</td>\n",
       "      <td>convenient assembling</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927525</th>\n",
       "      <td>9995315</td>\n",
       "      <td>9995315_37</td>\n",
       "      <td>stator</td>\n",
       "      <td>in</td>\n",
       "      <td>motor housing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927526</th>\n",
       "      <td>9995315</td>\n",
       "      <td>9995315_37</td>\n",
       "      <td>stator</td>\n",
       "      <td>in</td>\n",
       "      <td>cover</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927527</th>\n",
       "      <td>9995315</td>\n",
       "      <td>9995315_37</td>\n",
       "      <td>cover</td>\n",
       "      <td>of</td>\n",
       "      <td>ceiling fan motor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927528</th>\n",
       "      <td>9995315</td>\n",
       "      <td>9995315_37</td>\n",
       "      <td>cover</td>\n",
       "      <td>is increased for</td>\n",
       "      <td>convenient assembling</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2927529 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        patent_id sentence_id                head              relation  \\\n",
       "0        10001020  10001020_0   present invention  generally relates to   \n",
       "1        10001020  10001020_0   present invention  generally relates to   \n",
       "2        10001020  10001020_0   present invention  generally relates to   \n",
       "3        10001020  10001020_0   present invention  generally relates to   \n",
       "4        10001020  10001020_0   present invention     generally relates   \n",
       "...           ...         ...                 ...                   ...   \n",
       "2927524   9995315  9995315_37  wire winding space      is increased for   \n",
       "2927525   9995315  9995315_37              stator                    in   \n",
       "2927526   9995315  9995315_37              stator                    in   \n",
       "2927527   9995315  9995315_37               cover                    of   \n",
       "2927528   9995315  9995315_37               cover      is increased for   \n",
       "\n",
       "                          tail  \n",
       "0                         fans  \n",
       "1               fan assemblies  \n",
       "2                   fan wheels  \n",
       "3         composite fan blades  \n",
       "4                   attachment  \n",
       "...                        ...  \n",
       "2927524  convenient assembling  \n",
       "2927525          motor housing  \n",
       "2927526                  cover  \n",
       "2927527      ceiling fan motor  \n",
       "2927528  convenient assembling  \n",
       "\n",
       "[2927529 rows x 5 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#import the knowledge base\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "facts = pd.read_pickle(\"data/fan-systems-facts.pkl\")\n",
    "facts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "803c899b-4a95-4858-9183-c2450a96b3be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>head</th>\n",
       "      <th>relation</th>\n",
       "      <th>tail</th>\n",
       "      <th>facts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001020</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fans</td>\n",
       "      <td>present invention :: generally relates to :: fans</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001020</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fan assemblies</td>\n",
       "      <td>present invention :: generally relates to :: f...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001020</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>fan wheels</td>\n",
       "      <td>present invention :: generally relates to :: f...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001020</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates to</td>\n",
       "      <td>composite fan blades</td>\n",
       "      <td>present invention :: generally relates to :: c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001020</td>\n",
       "      <td>present invention</td>\n",
       "      <td>generally relates</td>\n",
       "      <td>attachment</td>\n",
       "      <td>present invention :: generally relates :: atta...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927524</th>\n",
       "      <td>9995315</td>\n",
       "      <td>wire winding space</td>\n",
       "      <td>is increased for</td>\n",
       "      <td>convenient assembling</td>\n",
       "      <td>wire winding space :: is increased for :: conv...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927525</th>\n",
       "      <td>9995315</td>\n",
       "      <td>stator</td>\n",
       "      <td>in</td>\n",
       "      <td>motor housing</td>\n",
       "      <td>stator :: in :: motor housing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927526</th>\n",
       "      <td>9995315</td>\n",
       "      <td>stator</td>\n",
       "      <td>in</td>\n",
       "      <td>cover</td>\n",
       "      <td>stator :: in :: cover</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927527</th>\n",
       "      <td>9995315</td>\n",
       "      <td>cover</td>\n",
       "      <td>of</td>\n",
       "      <td>ceiling fan motor</td>\n",
       "      <td>cover :: of :: ceiling fan motor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2927528</th>\n",
       "      <td>9995315</td>\n",
       "      <td>cover</td>\n",
       "      <td>is increased for</td>\n",
       "      <td>convenient assembling</td>\n",
       "      <td>cover :: is increased for :: convenient assemb...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1995210 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        patent_id                head              relation  \\\n",
       "0        10001020   present invention  generally relates to   \n",
       "1        10001020   present invention  generally relates to   \n",
       "2        10001020   present invention  generally relates to   \n",
       "3        10001020   present invention  generally relates to   \n",
       "4        10001020   present invention     generally relates   \n",
       "...           ...                 ...                   ...   \n",
       "2927524   9995315  wire winding space      is increased for   \n",
       "2927525   9995315              stator                    in   \n",
       "2927526   9995315              stator                    in   \n",
       "2927527   9995315               cover                    of   \n",
       "2927528   9995315               cover      is increased for   \n",
       "\n",
       "                          tail  \\\n",
       "0                         fans   \n",
       "1               fan assemblies   \n",
       "2                   fan wheels   \n",
       "3         composite fan blades   \n",
       "4                   attachment   \n",
       "...                        ...   \n",
       "2927524  convenient assembling   \n",
       "2927525          motor housing   \n",
       "2927526                  cover   \n",
       "2927527      ceiling fan motor   \n",
       "2927528  convenient assembling   \n",
       "\n",
       "                                                     facts  \n",
       "0        present invention :: generally relates to :: fans  \n",
       "1        present invention :: generally relates to :: f...  \n",
       "2        present invention :: generally relates to :: f...  \n",
       "3        present invention :: generally relates to :: c...  \n",
       "4        present invention :: generally relates :: atta...  \n",
       "...                                                    ...  \n",
       "2927524  wire winding space :: is increased for :: conv...  \n",
       "2927525                      stator :: in :: motor housing  \n",
       "2927526                              stator :: in :: cover  \n",
       "2927527                   cover :: of :: ceiling fan motor  \n",
       "2927528  cover :: is increased for :: convenient assemb...  \n",
       "\n",
       "[1995210 rows x 5 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#removing duplicate facts within patents\n",
    "\n",
    "facts = facts.drop(columns=[\"sentence_id\"]).drop_duplicates()\n",
    "facts[\"facts\"] = facts[\"head\"] + \" :: \" + facts[\"relation\"] + \" :: \" + facts[\"tail\"]\n",
    "\n",
    "facts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0cbb12e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unique_entities</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>plurality</td>\n",
       "      <td>52465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>fan</td>\n",
       "      <td>44387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>air</td>\n",
       "      <td>38567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>each</td>\n",
       "      <td>27595</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>motor</td>\n",
       "      <td>25475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261346</th>\n",
       "      <td>chiller system</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261347</th>\n",
       "      <td>recirculation feature</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261348</th>\n",
       "      <td>stage high pressure compressor</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261349</th>\n",
       "      <td>above points</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261350</th>\n",
       "      <td>these special flow conducting elements</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>261351 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                               unique_entities  counts\n",
       "0                                    plurality   52465\n",
       "1                                          fan   44387\n",
       "2                                          air   38567\n",
       "3                                         each   27595\n",
       "4                                        motor   25475\n",
       "...                                        ...     ...\n",
       "261346                          chiller system       1\n",
       "261347                   recirculation feature       1\n",
       "261348          stage high pressure compressor       1\n",
       "261349                            above points       1\n",
       "261350  these special flow conducting elements       1\n",
       "\n",
       "[261351 rows x 2 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#sort entities according to frequency\n",
    "\n",
    "ent_counts = pd.concat([facts[\"head\"], facts[\"tail\"]]).value_counts().rename_axis('unique_entities').reset_index(name='counts')\n",
    "ent_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a034d66d-faef-4002-ac3b-78ef1e0be2e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>unique_entities</th>\n",
       "      <th>counts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>fan blades</td>\n",
       "      <td>10530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>fan blade</td>\n",
       "      <td>7990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>air flow</td>\n",
       "      <td>7970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>fan assembly</td>\n",
       "      <td>7834</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>ceiling fan</td>\n",
       "      <td>6518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>axial direction</td>\n",
       "      <td>5715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>leading edge</td>\n",
       "      <td>5326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>radial direction</td>\n",
       "      <td>4916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>air outlet</td>\n",
       "      <td>4823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>electric motor</td>\n",
       "      <td>4369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>centrifugal fan</td>\n",
       "      <td>4339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>trailing edge</td>\n",
       "      <td>4320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>air inlet</td>\n",
       "      <td>4067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>each blade</td>\n",
       "      <td>3966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>gas turbine engine</td>\n",
       "      <td>3461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>inner surface</td>\n",
       "      <td>3421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105</th>\n",
       "      <td>fan housing</td>\n",
       "      <td>3357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>circumferential direction</td>\n",
       "      <td>3330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108</th>\n",
       "      <td>fan motor</td>\n",
       "      <td>3320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>outer surface</td>\n",
       "      <td>3247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>cooling fan</td>\n",
       "      <td>3087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>128</th>\n",
       "      <td>central axis</td>\n",
       "      <td>3075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>129</th>\n",
       "      <td>fan wheel</td>\n",
       "      <td>3074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>motor housing</td>\n",
       "      <td>3049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136</th>\n",
       "      <td>circuit board</td>\n",
       "      <td>2914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>heat exchanger</td>\n",
       "      <td>2669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>fan unit</td>\n",
       "      <td>2666</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>168</th>\n",
       "      <td>outer periphery</td>\n",
       "      <td>2473</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>171</th>\n",
       "      <td>axial fan</td>\n",
       "      <td>2434</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>upper surface</td>\n",
       "      <td>2413</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               unique_entities  counts\n",
       "17                  fan blades   10530\n",
       "28                   fan blade    7990\n",
       "29                    air flow    7970\n",
       "30                fan assembly    7834\n",
       "45                 ceiling fan    6518\n",
       "52             axial direction    5715\n",
       "55                leading edge    5326\n",
       "62            radial direction    4916\n",
       "64                  air outlet    4823\n",
       "74              electric motor    4369\n",
       "75             centrifugal fan    4339\n",
       "78               trailing edge    4320\n",
       "83                   air inlet    4067\n",
       "84                  each blade    3966\n",
       "99          gas turbine engine    3461\n",
       "101              inner surface    3421\n",
       "105                fan housing    3357\n",
       "106  circumferential direction    3330\n",
       "108                  fan motor    3320\n",
       "113              outer surface    3247\n",
       "125                cooling fan    3087\n",
       "128               central axis    3075\n",
       "129                  fan wheel    3074\n",
       "131              motor housing    3049\n",
       "136              circuit board    2914\n",
       "148             heat exchanger    2669\n",
       "150                   fan unit    2666\n",
       "168            outer periphery    2473\n",
       "171                  axial fan    2434\n",
       "174              upper surface    2413"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#filter top 30 entities with 2 or more words\n",
    "\n",
    "ent_counts = ent_counts.loc[ent_counts[\"unique_entities\"].str.contains(\" \")]\n",
    "\n",
    "#removing general entities\n",
    "\n",
    "terms = [\"present invention\", \"present disclosure\", \"preferred embodiment\"]\n",
    "ent_counts = ent_counts.loc[~ent_counts[\"unique_entities\"].isin(terms)]\n",
    "\n",
    "ent_counts.head(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e7c00572",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>head</th>\n",
       "      <th>relation</th>\n",
       "      <th>tail</th>\n",
       "      <th>facts</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>9033674</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>5577888</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>6755615</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>6726451</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>6634855</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1827</th>\n",
       "      <td>11236762</td>\n",
       "      <td>centrifugal fan</td>\n",
       "      <td>has</td>\n",
       "      <td>fan wheel</td>\n",
       "      <td>centrifugal fan :: has :: fan wheel</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1822</th>\n",
       "      <td>11231041</td>\n",
       "      <td>fan housing</td>\n",
       "      <td>with</td>\n",
       "      <td>fan blades</td>\n",
       "      <td>fan housing :: with :: fan blades</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1821</th>\n",
       "      <td>11231041</td>\n",
       "      <td>inner surface</td>\n",
       "      <td>of</td>\n",
       "      <td>fan housing</td>\n",
       "      <td>inner surface :: of :: fan housing</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1820</th>\n",
       "      <td>11231040</td>\n",
       "      <td>fan wheel</td>\n",
       "      <td>of</td>\n",
       "      <td>fan assembly</td>\n",
       "      <td>fan wheel :: of :: fan assembly</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3300</th>\n",
       "      <td>9995305</td>\n",
       "      <td>fan blades</td>\n",
       "      <td>selected to optimize</td>\n",
       "      <td>air flow</td>\n",
       "      <td>fan blades :: selected to optimize :: air flow</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3301 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     patent_id             head              relation           tail  \\\n",
       "100    9033674     leading edge                    to  trailing edge   \n",
       "71     5577888     leading edge                    to  trailing edge   \n",
       "82     6755615     leading edge                    to  trailing edge   \n",
       "81     6726451     leading edge                    to  trailing edge   \n",
       "80     6634855     leading edge                    to  trailing edge   \n",
       "...        ...              ...                   ...            ...   \n",
       "1827  11236762  centrifugal fan                   has      fan wheel   \n",
       "1822  11231041      fan housing                  with     fan blades   \n",
       "1821  11231041    inner surface                    of    fan housing   \n",
       "1820  11231040        fan wheel                    of   fan assembly   \n",
       "3300   9995305       fan blades  selected to optimize       air flow   \n",
       "\n",
       "                                               facts  count  \n",
       "100              leading edge :: to :: trailing edge     80  \n",
       "71               leading edge :: to :: trailing edge     80  \n",
       "82               leading edge :: to :: trailing edge     80  \n",
       "81               leading edge :: to :: trailing edge     80  \n",
       "80               leading edge :: to :: trailing edge     80  \n",
       "...                                              ...    ...  \n",
       "1827             centrifugal fan :: has :: fan wheel      1  \n",
       "1822               fan housing :: with :: fan blades      1  \n",
       "1821              inner surface :: of :: fan housing      1  \n",
       "1820                 fan wheel :: of :: fan assembly      1  \n",
       "3300  fan blades :: selected to optimize :: air flow      1  \n",
       "\n",
       "[3301 rows x 6 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#sort facts based on patent frequency\n",
    "\n",
    "freq_ents = ent_counts.head(30)[\"unique_entities\"].tolist()\n",
    "facts = facts.loc[(facts[\"head\"].isin(freq_ents)) & (facts[\"tail\"].isin(freq_ents)) & (facts[\"head\"] != facts[\"tail\"])]\n",
    "facts = pd.merge(facts, facts[\"facts\"].value_counts(), on=\"facts\").sort_values(by=\"count\", ascending=False)\n",
    "facts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1b5d4671",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>head</th>\n",
       "      <th>relation</th>\n",
       "      <th>tail</th>\n",
       "      <th>facts</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9033674</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>to</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>leading edge :: to :: trailing edge</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4995787</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>of</td>\n",
       "      <td>each blade</td>\n",
       "      <td>leading edge :: of :: each blade</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8070447</td>\n",
       "      <td>leading edge</td>\n",
       "      <td>of</td>\n",
       "      <td>fan blade</td>\n",
       "      <td>leading edge :: of :: fan blade</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9239062</td>\n",
       "      <td>fan blade</td>\n",
       "      <td>for</td>\n",
       "      <td>gas turbine engine</td>\n",
       "      <td>fan blade :: for :: gas turbine engine</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8727700</td>\n",
       "      <td>outer periphery</td>\n",
       "      <td>of</td>\n",
       "      <td>fan wheel</td>\n",
       "      <td>outer periphery :: of :: fan wheel</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>172</th>\n",
       "      <td>9587645</td>\n",
       "      <td>gas turbine engine</td>\n",
       "      <td>comprising</td>\n",
       "      <td>trailing edge</td>\n",
       "      <td>gas turbine engine :: comprising :: trailing edge</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>173</th>\n",
       "      <td>10767658</td>\n",
       "      <td>axial fan</td>\n",
       "      <td>wherein</td>\n",
       "      <td>inner surface</td>\n",
       "      <td>axial fan :: wherein :: inner surface</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>10816005</td>\n",
       "      <td>fan blades</td>\n",
       "      <td>mechanically coupled to</td>\n",
       "      <td>circuit board</td>\n",
       "      <td>fan blades :: mechanically coupled to :: circu...</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>9194398</td>\n",
       "      <td>centrifugal fan</td>\n",
       "      <td>improve</td>\n",
       "      <td>air flow</td>\n",
       "      <td>centrifugal fan :: improve :: air flow</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>6644918</td>\n",
       "      <td>air flow</td>\n",
       "      <td>from</td>\n",
       "      <td>fan motor</td>\n",
       "      <td>air flow :: from :: fan motor</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>177 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    patent_id                head                 relation  \\\n",
       "0     9033674        leading edge                       to   \n",
       "1     4995787        leading edge                       of   \n",
       "2     8070447        leading edge                       of   \n",
       "3     9239062           fan blade                      for   \n",
       "4     8727700     outer periphery                       of   \n",
       "..        ...                 ...                      ...   \n",
       "172   9587645  gas turbine engine               comprising   \n",
       "173  10767658           axial fan                  wherein   \n",
       "174  10816005          fan blades  mechanically coupled to   \n",
       "175   9194398     centrifugal fan                  improve   \n",
       "176   6644918            air flow                     from   \n",
       "\n",
       "                   tail                                              facts  \\\n",
       "0         trailing edge                leading edge :: to :: trailing edge   \n",
       "1            each blade                   leading edge :: of :: each blade   \n",
       "2             fan blade                    leading edge :: of :: fan blade   \n",
       "3    gas turbine engine             fan blade :: for :: gas turbine engine   \n",
       "4             fan wheel                 outer periphery :: of :: fan wheel   \n",
       "..                  ...                                                ...   \n",
       "172       trailing edge  gas turbine engine :: comprising :: trailing edge   \n",
       "173       inner surface              axial fan :: wherein :: inner surface   \n",
       "174       circuit board  fan blades :: mechanically coupled to :: circu...   \n",
       "175            air flow             centrifugal fan :: improve :: air flow   \n",
       "176           fan motor                      air flow :: from :: fan motor   \n",
       "\n",
       "     count  \n",
       "0       80  \n",
       "1       31  \n",
       "2       30  \n",
       "3       26  \n",
       "4       23  \n",
       "..     ...  \n",
       "172      2  \n",
       "173      2  \n",
       "174      2  \n",
       "175      2  \n",
       "176      2  \n",
       "\n",
       "[177 rows x 6 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#selecting the most frequent relation between each pair of frequent entities\n",
    "\n",
    "from itertools import product\n",
    "\n",
    "pairs = [(h, t) for (h, t) in list(product(freq_ents, freq_ents)) if h != t]\n",
    "\n",
    "freq_facts = []\n",
    "for index, row in facts.iterrows():\n",
    "    if len(pairs) > 0:\n",
    "        for h, t in pairs:\n",
    "            if ((h, t) == (row[\"head\"], row[\"tail\"])) & (row[\"count\"] > 1):\n",
    "                freq_facts.append({\n",
    "                    \"patent_id\": row[\"patent_id\"],\n",
    "                    \"head\": row[\"head\"],\n",
    "                    \"relation\": row[\"relation\"],\n",
    "                    \"tail\": row[\"tail\"],\n",
    "                    \"facts\": row[\"facts\"],\n",
    "                    \"count\": row[\"count\"]\n",
    "                })\n",
    "                pairs.remove((h, t))\n",
    "                pairs.remove((t, h))\n",
    "                break\n",
    "\n",
    "selected_facts = pd.DataFrame(freq_facts)\n",
    "selected_facts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e67025b8-d87c-4c73-9592-6d42c4b66ca2",
   "metadata": {},
   "outputs": [],
   "source": [
    "#converting data frame to a dictionary\n",
    "\n",
    "import pickle\n",
    "\n",
    "edges = {}\n",
    "titles = {}\n",
    "\n",
    "for index, row in selected_facts.iterrows():\n",
    "    edges[(row[\"head\"], row[\"tail\"])] = row[\"relation\"]\n",
    "    titles[(row[\"head\"], row[\"tail\"])] = f\"This fact has been mentioned in {row['count']} patents, e.g., in US{row['patent_id']}.\"\n",
    "\n",
    "with open(\"data/generalisable-facts.pkl\", \"wb\") as f:\n",
    "    pickle.dump(edges, f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "82c38e8b-5621-4a74-b73f-1eab25c40a4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "generalisable-facts.html\n"
     ]
    }
   ],
   "source": [
    "#visualising the selected facts\n",
    "from pyvis.network import Network\n",
    "import random\n",
    "\n",
    "g = Network(width=\"100%\", height=\"1600px\", directed =True)\n",
    "\n",
    "nodes = ent_counts.head(30)[\"unique_entities\"].tolist()\n",
    "sizes = [item/1000 for item in ent_counts.head(30)[\"counts\"].tolist()]\n",
    "labels = [f\"This entity has been mentioned in {item} facts.\" for item in ent_counts.head(30)[\"counts\"].tolist()]\n",
    "colors = [\"#A9A9A9\"  for item in nodes]\n",
    "\n",
    "g.add_nodes(nodes, size=sizes, color=colors, title=labels)\n",
    "\n",
    "for h, t in edges:\n",
    "    #including an edge by chance to ensure the visualisation is readable\n",
    "    if random.random() < 0.3:\n",
    "        g.add_edge(source=h, to=t, label=edges[(h, t)], color=\"#D3D3D3\", title=titles[h, t])\n",
    "\n",
    "g.show(f\"generalisable-facts.html\", notebook=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "00950bff-d48f-445b-bfa8-91d3d7835d0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#shuffling the selected facts\n",
    "\n",
    "facts_to_text = selected_facts[\"facts\"].tolist()\n",
    "random.shuffle(facts_to_text)\n",
    "\n",
    "with open(\"data/generalisable-facts.txt\", \"w+\", encoding=\"utf-8\") as f:\n",
    "    f.write(\"\\n\".join(facts_to_text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "94555763-12b9-46f1-ab1d-ec287194175d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>patent_date</th>\n",
       "      <th>description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1838344</th>\n",
       "      <td>11853544</td>\n",
       "      <td>2023-12-26</td>\n",
       "      <td>Electronic device, method for driving electron...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1836877</th>\n",
       "      <td>11852059</td>\n",
       "      <td>2023-12-26</td>\n",
       "      <td>Noise muffler for an air moving device. A nois...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1836866</th>\n",
       "      <td>11852048</td>\n",
       "      <td>2023-12-26</td>\n",
       "      <td>Gas admission valve (GAV) assembly and system ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1836867</th>\n",
       "      <td>11852049</td>\n",
       "      <td>2023-12-26</td>\n",
       "      <td>Electric actuator. A differential device (5) o...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1836868</th>\n",
       "      <td>11852050</td>\n",
       "      <td>2023-12-26</td>\n",
       "      <td>Support arrangement for an actuator of a cam p...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735925</th>\n",
       "      <td>6838900</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>Middle pull-up point-to-point transceiving bus...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735924</th>\n",
       "      <td>6838899</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>Apparatus and method of error detection and co...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735923</th>\n",
       "      <td>6838898</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>Apparatus and method for testing high current ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735922</th>\n",
       "      <td>6838897</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>Integrated circuit test system and method. The...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4736175</th>\n",
       "      <td>6839152</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>Adaptive filtering method and apparatus for de...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4972616 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        patent_id patent_date  \\\n",
       "1838344  11853544  2023-12-26   \n",
       "1836877  11852059  2023-12-26   \n",
       "1836866  11852048  2023-12-26   \n",
       "1836867  11852049  2023-12-26   \n",
       "1836868  11852050  2023-12-26   \n",
       "...           ...         ...   \n",
       "4735925   6838900  2005-01-04   \n",
       "4735924   6838899  2005-01-04   \n",
       "4735923   6838898  2005-01-04   \n",
       "4735922   6838897  2005-01-04   \n",
       "4736175   6839152  2005-01-04   \n",
       "\n",
       "                                               description  \n",
       "1838344  Electronic device, method for driving electron...  \n",
       "1836877  Noise muffler for an air moving device. A nois...  \n",
       "1836866  Gas admission valve (GAV) assembly and system ...  \n",
       "1836867  Electric actuator. A differential device (5) o...  \n",
       "1836868  Support arrangement for an actuator of a cam p...  \n",
       "...                                                    ...  \n",
       "4735925  Middle pull-up point-to-point transceiving bus...  \n",
       "4735924  Apparatus and method of error detection and co...  \n",
       "4735923  Apparatus and method for testing high current ...  \n",
       "4735922  Integrated circuit test system and method. The...  \n",
       "4736175  Adaptive filtering method and apparatus for de...  \n",
       "\n",
       "[4972616 rows x 3 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#gathering patent data\n",
    "\n",
    "patents = pd.read_pickle(\"data/patents.pkl\")\n",
    "patents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f7ea6595-e4ca-4417-ac0b-79071a90bd6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patent_id</th>\n",
       "      <th>patent_date</th>\n",
       "      <th>description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1353749</th>\n",
       "      <td>11364772</td>\n",
       "      <td>2022-06-21</td>\n",
       "      <td>Patent: 11364772. Air conditioning unit. An ai...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1232866</th>\n",
       "      <td>11242862</td>\n",
       "      <td>2022-02-08</td>\n",
       "      <td>Patent: 11242862. Blower device. A blower devi...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>324966</th>\n",
       "      <td>10327392</td>\n",
       "      <td>2019-06-25</td>\n",
       "      <td>Patent: 10327392. Battery-powered debris blowe...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1090193</th>\n",
       "      <td>11098953</td>\n",
       "      <td>2021-08-24</td>\n",
       "      <td>Patent: 11098953. Integrated fan heat exchange...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>476909</th>\n",
       "      <td>10480520</td>\n",
       "      <td>2019-11-19</td>\n",
       "      <td>Patent: 10480520. Motor-driven fan with an ass...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7103171</th>\n",
       "      <td>9217440</td>\n",
       "      <td>2015-12-22</td>\n",
       "      <td>Patent: 9217440. Ceiling fan. A ceiling fan in...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974947</th>\n",
       "      <td>10982681</td>\n",
       "      <td>2021-04-20</td>\n",
       "      <td>Patent: 10982681. Fan blade structure and cent...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6983757</th>\n",
       "      <td>9097261</td>\n",
       "      <td>2015-08-04</td>\n",
       "      <td>Patent: 9097261. Axial fan with flow guide bod...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>491367</th>\n",
       "      <td>10495114</td>\n",
       "      <td>2019-12-03</td>\n",
       "      <td>Patent: 10495114. Blower. A blower fan include...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885622</th>\n",
       "      <td>10892606</td>\n",
       "      <td>2021-01-12</td>\n",
       "      <td>Patent: 10892606. Ventilation unit for electri...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        patent_id patent_date  \\\n",
       "1353749  11364772  2022-06-21   \n",
       "1232866  11242862  2022-02-08   \n",
       "324966   10327392  2019-06-25   \n",
       "1090193  11098953  2021-08-24   \n",
       "476909   10480520  2019-11-19   \n",
       "7103171   9217440  2015-12-22   \n",
       "974947   10982681  2021-04-20   \n",
       "6983757   9097261  2015-08-04   \n",
       "491367   10495114  2019-12-03   \n",
       "885622   10892606  2021-01-12   \n",
       "\n",
       "                                               description  \n",
       "1353749  Patent: 11364772. Air conditioning unit. An ai...  \n",
       "1232866  Patent: 11242862. Blower device. A blower devi...  \n",
       "324966   Patent: 10327392. Battery-powered debris blowe...  \n",
       "1090193  Patent: 11098953. Integrated fan heat exchange...  \n",
       "476909   Patent: 10480520. Motor-driven fan with an ass...  \n",
       "7103171  Patent: 9217440. Ceiling fan. A ceiling fan in...  \n",
       "974947   Patent: 10982681. Fan blade structure and cent...  \n",
       "6983757  Patent: 9097261. Axial fan with flow guide bod...  \n",
       "491367   Patent: 10495114. Blower. A blower fan include...  \n",
       "885622   Patent: 10892606. Ventilation unit for electri...  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Select the 10 random patents related to fan systems\n",
    "\n",
    "patents = patents.loc[patents[\"patent_id\"].isin(facts[\"patent_id\"].unique().tolist())]\n",
    "patents = patents.sample(10)\n",
    "patents[\"description\"] = \"Patent: \" + patents[\"patent_id\"] + \". \" + patents[\"description\"]\n",
    "\n",
    "patents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0f76630a-5197-4888-bd40-281ee6f0b810",
   "metadata": {},
   "outputs": [],
   "source": [
    "#getting the list of abstracts as text file\n",
    "\n",
    "with open(\"data/domain-knowledge-text.txt\", \"w+\", encoding=\"utf-8\") as f:\n",
    "    f.write(\"\\n\\n\".join(patents[\"description\"].tolist()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
